 

package com.zdkj.subway.stm.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.digest.MD5;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.admin.api.entity.SysDictItem;
import com.zdkj.common.core.constant.CommonConstants;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.stm.annotation.SwStmNoRepeatSubmitBaseController;
import com.zdkj.subway.stm.constant.StmConstans;
import com.zdkj.subway.stm.constant.StmTableCommon;
import com.zdkj.subway.stm.dto.in.SwStTvmCheckDetailDTO;
import com.zdkj.subway.stm.dvo.SwStmStationDataEntryLogDvo;
import com.zdkj.subway.stm.entity.*;
import com.zdkj.subway.stm.fegin.SystemUserService;
import com.zdkj.subway.stm.service.SwStTvmCheckDetailService;
import com.zdkj.subway.stm.service.SwStmStationDataEntryLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.net.URLEncoder;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * TVM详细日清点表（主表）
 *
 * @author songtuo
 * @date 2020-03-05 21:04:12
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swsttvmcheckdetail" )
@Api(value = "swsttvmcheckdetail", tags = "TVM详细日清点表（主表）管理")
@Slf4j
public class    SwStTvmCheckDetailController extends SwStmNoRepeatSubmitBaseController {

    private final  SwStTvmCheckDetailService swStTvmCheckDetailService;

    private final SystemUserService systemUserService;

    private final SwStmStationDataEntryLogService swStmStationDataEntryLogService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    /**
     * 分页查询
     * @param page 分页对象
     * @param swStTvmCheckDetail TVM详细日清点表（主表）
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R getSwStTvmCheckDetailPage(Page page, SwStTvmCheckDetail swStTvmCheckDetail) {
        SwStTvmCheckDetail swStTvmCheckDetailObj = ObjectUtils.getDefaultObj(SwStTvmCheckDetail.class);
        swStTvmCheckDetail.setLineCode(swStTvmCheckDetailObj.getLineCode());
        swStTvmCheckDetail.setStationCode(swStTvmCheckDetailObj.getStationCode());
        return R.ok(swStTvmCheckDetailService.page(page, Wrappers.query(swStTvmCheckDetail).orderByDesc("-APPROVAL_STATUS","REVENUE_TIME","TVM_CODE")));
    }

    /**
     * 查询
     * @return
     */
    @ApiOperation(value = "查询", notes = "查询")
    @GetMapping("/queryTVM")
    public R querySwStTvmCheckDetail(SwStTvmCheckDetail swStTvmCheckDetail) {
        return R.ok(swStTvmCheckDetailService.list(Wrappers.query(swStTvmCheckDetail)));
    }


    /**
     * 通过id查询TVM详细日清点表（主表）
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(swStTvmCheckDetailService.getById(id));
    }

    /**
     * 新增TVM详细日清点表（主表）
     * @param swStTvmCheckDetailDTO TVM详细日清点表（主表）
     * @return R
     */
    @ApiOperation(value = "新增TVM详细日清点表（主表）", notes = "新增TVM详细日清点表（主表）")
    @SysLog("新增TVM详细日清点表（主表）" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('swsttvmcheckdetail_add')" )
    public R save(@RequestBody SwStTvmCheckDetailDTO swStTvmCheckDetailDTO) {
        return R.ok(swStTvmCheckDetailService.saveSwStTvmCheckDetail(swStTvmCheckDetailDTO));
    }

    /**
     * 修改TVM详细日清点表（主表）
     * @param swStTvmCheckDetailDTO TVM详细日清点表（主表）
     * @return R
     */
    @ApiOperation(value = "修改TVM详细日清点表（主表）", notes = "修改TVM详细日清点表（主表）")
    @SysLog("修改TVM详细日清点表（主表）" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('swsttvmcheckdetail_edit')" )
    public R updateById(@RequestBody SwStTvmCheckDetailDTO swStTvmCheckDetailDTO) {
        SwStTvmCheckDetail checkDetail = swStTvmCheckDetailService.getById(swStTvmCheckDetailDTO.getSwStTvmCheckDetail().getId());
        if(ObjectUtil.isNotEmpty(checkDetail)){
            String approvalStatus = checkDetail.getApprovalStatus();
            if("1".equals(approvalStatus)){
                return R.failed(StmConstans.failedEdit);
            }
        }
        return R.ok(swStTvmCheckDetailService.updateSwStTvmCheckDetail(swStTvmCheckDetailDTO));
    }

    @ApiOperation(value = "清点人确认（主表）", notes = "清点人确认（主表）")
    @PutMapping("/confirmBatch")
    @SysLog("清点人确认")
    @PreAuthorize("@pms.hasPermission('swsttvmcheckdetail_confirm')" )
    public R submit(@Valid @RequestBody List<Integer> ids) {
        return R.ok(swStTvmCheckDetailService.confirmBatch(ids));
    }

    /**
     * 通过id删除TVM详细日清点表（主表）
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除TVM详细日清点表（主表）", notes = "通过id删除TVM详细日清点表（主表）")
    @SysLog("通过id删除TVM详细日清点表（主表）" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('swsttvmcheckdetail_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(swStTvmCheckDetailService.deleteCascadeById(id));
    }

    /**
     * 查询tvm日营收详情
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询具体的Tvm日营收信息详情", notes = "通过id查询")
    @GetMapping("/details/{id}/{flag}" )
    public R getSwTvmCheckDetails(@PathVariable("id" ) Integer id,@PathVariable("flag" ) String flag) {
        return R.ok(swStTvmCheckDetailService.queryDetailsByid(id,flag));
    }


    /**
     * 通过id查询TVM详细日清点表（主表）历史记录
     *
     * @param  id
     * @return R
     */
    @ApiOperation(value = "通过id查询TVM详细日清点表（主表）历史记录", notes = "通过id查询TVM详细日清点表（主表）历史记录")
    @GetMapping("getLogById/{id}")
    public R getLogById(@PathVariable("id") Integer id) {
        List<SwStmStationDataEntryLogDvo> LogInfoList = new ArrayList<>();
        List<SwStmStationDataEntryLog> swStmStationDataEntryLogs = swStmStationDataEntryLogService.getBaseMapper()
                .selectList(Wrappers.<SwStmStationDataEntryLog>lambdaQuery()
                        .eq(SwStmStationDataEntryLog::getRelationId, id)
                        .eq(SwStmStationDataEntryLog::getLogTableName, StmTableCommon.SW_ST_TVM_CHECK_DETAIL));
        //返回json串
        if(CollectionUtil.isNotEmpty(swStmStationDataEntryLogs)){
            swStmStationDataEntryLogs.stream().forEach(x -> {
                JSONObject jsonObject = JSONObject.parseObject(x.getLogInfo());
                SwStmStationDataEntryLogDvo swStmStationDataEntryLogDvo = new SwStmStationDataEntryLogDvo();
                BeanUtils.copyProperties(x,swStmStationDataEntryLogDvo);
                swStmStationDataEntryLogDvo.setLogInfo(jsonObject);
                LogInfoList.add(swStmStationDataEntryLogDvo);
            });
        }
        //List<String> LogInfoList = swStmStationDataEntryLogs.stream().map(SwStmStationDataEntryLog::getLogInfo).collect(Collectors.toList());
        return R.ok(LogInfoList);
    }

    /**
     * 通过记录表主表id查询具体的手工清出数据详情历史记录
     *
     * @param  id
     * @return R
     */
    @ApiOperation(value = "通过记录表主表id查询具体的手工清出数据详情历史记录", notes = "通过记录表主表id查询具体的手工清出数据详情历史记录")
    @GetMapping("getLogChildById/{id}")
    public R getLogChildById(@PathVariable("id") Integer id) {
        return R.ok(swStmStationDataEntryLogService.mapListTvmCheckDetails(id));
    }

    /**
     * 批量删除子表
     *
     * @param idList
     * @return
     */
    @SysLog("通过id批量删除TVM详细日清点表")
    @DeleteMapping("/batchCascadeDel")
    @PreAuthorize("@pms.hasPermission('swsttvmcheckdetail_batch_del')")
    @Transactional
    @ApiOperation(value = "通过id批量删除TVM详细日清点表", notes = "通过id批量删除TVM详细日清点表")
    public R batchRemoveById(@RequestBody List<Integer> idList) {
        List<SwStTvmCheckDetail> list = swStTvmCheckDetailService.list(new QueryWrapper<SwStTvmCheckDetail>().lambda().in(SwStTvmCheckDetail::getId, idList));
        List<Integer> deleteIds = list.stream().filter(x -> !x.getApprovalStatus().equals(CommonConstants.SUBMIT)).map(x -> x.getId()).collect(Collectors.toList());
        if(CollectionUtil.isEmpty(deleteIds)){
            return R.failed(StmConstans.failedDelete);
        }
        deleteIds.forEach(swStTvmCheckDetailService::deleteCascadeById);
        return R.ok();
    }

    /**
     * 单个新增或者修改tvm详细日清点表（主表）
     * @param swStTvmCheckDetailDTO TVM详细日清点表（主表）
     * @return R
     */
    @ApiOperation(value = "单个新增tvm详细日清点表（主表）", notes = "单个新增或者修改tvm详细日清点表（主表）")
    @SysLog("单个新增或者修改tvm详细日清点表" )
    @PutMapping("/saveorupdate")
    @PreAuthorize("@pms.hasPermission('swsttvmcheckdetail_save_or_update')" )
    public R saveOrUpdateStTvmCheckDetail(@RequestBody SwStTvmCheckDetailDTO swStTvmCheckDetailDTO,Integer id) throws SQLException {
        if(id==1){
            //判断添加操作所添加TVM数据是否存在并已提交数据
            SwStTvmCheckDetail swStTvmCheckDetail = swStTvmCheckDetailDTO.getSwStTvmCheckDetail();
            List<SwStTvmCheckDetailCoin> checkDetailCoins = swStTvmCheckDetailDTO.getSwStTvmCheckDetailCoins();
            List<SwStTvmCheckDetailCoinChange> checkDetailCoinChanges = swStTvmCheckDetailDTO.getSwStTvmCheckDetailCoinChanges();
            List<SwStTvmCheckDetailPaper> checkDetailPapers = swStTvmCheckDetailDTO.getSwStTvmCheckDetailPapers();
            List<SwStTvmCheckDetailPaperChange> checkDetailPaperChanges = swStTvmCheckDetailDTO.getSwStTvmCheckDetailPaperChanges();
            List<SwStTvmCheckDetailWaste> checkDetailWastes = swStTvmCheckDetailDTO.getSwStTvmCheckDetailWastes();
            //硬币回收箱
            if(CollectionUtil.isNotEmpty(checkDetailCoins)){
                for (SwStTvmCheckDetailCoin item : checkDetailCoins) {
                    QueryWrapper<SwStTvmCheckDetail> wrapper = new QueryWrapper<>();
                    wrapper.lambda().eq(SwStTvmCheckDetail::getLineCode,SecurityUtils.getUser().getLineCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getStationCode,SecurityUtils.getUser().getStationCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getRevenueTime,swStTvmCheckDetail.getRevenueTime());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getTvmCode,item.getTvmCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getApprovalStatus,CommonConstants.SUBMIT);
                    List<SwStTvmCheckDetail> checkDetail = swStTvmCheckDetailService.list(wrapper);
                    if(checkDetail.size()>0){
                        return R.failed(StmConstans.repetitionFailedInsert.replace("{tvmCode}", item.getTvmCode()));
                    }
                }
            }
            //硬币找零箱
            if(CollectionUtil.isNotEmpty(checkDetailCoinChanges)){
                for (SwStTvmCheckDetailCoinChange item : checkDetailCoinChanges) {
                    QueryWrapper<SwStTvmCheckDetail> wrapper = new QueryWrapper<>();
                    wrapper.lambda().eq(SwStTvmCheckDetail::getLineCode,SecurityUtils.getUser().getLineCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getStationCode,SecurityUtils.getUser().getStationCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getRevenueTime,swStTvmCheckDetail.getRevenueTime());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getTvmCode,item.getTvmCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getApprovalStatus,CommonConstants.SUBMIT);
                    List<SwStTvmCheckDetail> checkDetail = swStTvmCheckDetailService.list(wrapper);
                    if(checkDetail.size()>0){
                        return R.failed(StmConstans.repetitionFailedInsert.replace("{tvmCode}", item.getTvmCode()));
                    }
                }
            }
            //纸币回收箱
            if(CollectionUtil.isNotEmpty(checkDetailPapers)){
                for (SwStTvmCheckDetailPaper item : checkDetailPapers) {
                    QueryWrapper<SwStTvmCheckDetail> wrapper = new QueryWrapper<>();
                    wrapper.lambda().eq(SwStTvmCheckDetail::getLineCode,SecurityUtils.getUser().getLineCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getStationCode,SecurityUtils.getUser().getStationCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getRevenueTime,swStTvmCheckDetail.getRevenueTime());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getTvmCode,item.getTvmCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getApprovalStatus,CommonConstants.SUBMIT);
                    List<SwStTvmCheckDetail> checkDetail = swStTvmCheckDetailService.list(wrapper);
                    if(checkDetail.size()>0){
                        return R.failed(StmConstans.repetitionFailedInsert.replace("{tvmCode}", item.getTvmCode()));
                    }
                }
            }
            //纸币找零箱
            if(CollectionUtil.isNotEmpty(checkDetailPaperChanges)){
                for (SwStTvmCheckDetailPaperChange item : checkDetailPaperChanges) {
                    QueryWrapper<SwStTvmCheckDetail> wrapper = new QueryWrapper<>();
                    wrapper.lambda().eq(SwStTvmCheckDetail::getLineCode,SecurityUtils.getUser().getLineCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getStationCode,SecurityUtils.getUser().getStationCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getRevenueTime,swStTvmCheckDetail.getRevenueTime());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getTvmCode,item.getTvmCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getApprovalStatus,CommonConstants.SUBMIT);
                    List<SwStTvmCheckDetail> checkDetail = swStTvmCheckDetailService.list(wrapper);
                    if(checkDetail.size()>0){
                        return R.failed(StmConstans.repetitionFailedInsert.replace("{tvmCode}", item.getTvmCode()));
                    }
                }
            }
            //废钞箱
            if(CollectionUtil.isNotEmpty(checkDetailWastes)){
                for (SwStTvmCheckDetailWaste item : checkDetailWastes) {
                    QueryWrapper<SwStTvmCheckDetail> wrapper = new QueryWrapper<>();
                    wrapper.lambda().eq(SwStTvmCheckDetail::getLineCode,SecurityUtils.getUser().getLineCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getStationCode,SecurityUtils.getUser().getStationCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getRevenueTime,swStTvmCheckDetail.getRevenueTime());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getTvmCode,item.getTvmCode());
                    wrapper.lambda().eq(SwStTvmCheckDetail::getApprovalStatus,CommonConstants.SUBMIT);
                    List<SwStTvmCheckDetail> checkDetail = swStTvmCheckDetailService.list(wrapper);
                    if(checkDetail.size()>0){
                        return R.failed(StmConstans.repetitionFailedInsert.replace("{tvmCode}", item.getTvmCode()));
                    }
                }
            }
        }
        //硬币回收箱
        List<SwStTvmCheckDetailCoin> swStTvmCheckDetailCoins = swStTvmCheckDetailDTO.getSwStTvmCheckDetailCoins();
        if(CollectionUtil.isNotEmpty(swStTvmCheckDetailCoins)){
            //统计集合重复元素出现次数
            Map<String, Long> map1 = swStTvmCheckDetailCoins.stream().
                    collect(Collectors.groupingBy(x -> x.getTvmCode(), Collectors.counting()));
            for (Map.Entry<String, Long> tvm : map1.entrySet()) {
                if(!Long.valueOf(1).equals(tvm.getValue())){
                    return R.failed(StmConstans.failedInsert.replace("{TVMCODE}",tvm.getKey()));
                }
            }
        }

        //硬币找零箱
        List<SwStTvmCheckDetailCoinChange> swStTvmCheckDetailCoinChanges = swStTvmCheckDetailDTO.getSwStTvmCheckDetailCoinChanges();
        if(CollectionUtil.isNotEmpty(swStTvmCheckDetailCoinChanges)){
            //统计集合重复元素出现次数
            Map<String, Long> map2 = swStTvmCheckDetailCoinChanges.stream().
                    collect(Collectors.groupingBy(x -> x.getTvmCode(), Collectors.counting()));
            for (Map.Entry<String, Long> tvm : map2.entrySet()) {
                if(!Long.valueOf(1).equals(tvm.getValue())){
                    return R.failed(StmConstans.failedInsert.replace("{TVMCODE}",tvm.getKey()));
                }
            }
        }

        //纸币回收箱
        List<SwStTvmCheckDetailPaper> swStTvmCheckDetailPapers = swStTvmCheckDetailDTO.getSwStTvmCheckDetailPapers();
        if(CollectionUtil.isNotEmpty(swStTvmCheckDetailPapers)){
            //统计集合重复元素出现次数
            Map<String, Long> map3 = swStTvmCheckDetailPapers.stream().
                    collect(Collectors.groupingBy(x -> x.getTvmCode(), Collectors.counting()));
            for (Map.Entry<String, Long> tvm : map3.entrySet()) {
                if(!Long.valueOf(1).equals(tvm.getValue())){
                    return R.failed(StmConstans.failedInsert.replace("{TVMCODE}",tvm.getKey()));
                }
            }
        }

        //纸币找零箱
        List<SwStTvmCheckDetailPaperChange> swStTvmCheckDetailPaperChanges = swStTvmCheckDetailDTO.getSwStTvmCheckDetailPaperChanges();
        if(CollectionUtil.isNotEmpty(swStTvmCheckDetailPaperChanges)){
            //统计集合重复元素出现次数
            Map<String, Long> map4 = swStTvmCheckDetailPaperChanges.stream().
                    collect(Collectors.groupingBy(x -> x.getTvmCode(), Collectors.counting()));
            for (Map.Entry<String, Long> tvm : map4.entrySet()) {
                if(!Long.valueOf(1).equals(tvm.getValue())){
                    return R.failed(StmConstans.failedInsert.replace("{TVMCODE}",tvm.getKey()));
                }
            }
        }

        //废钞箱
        List<SwStTvmCheckDetailWaste> swStTvmCheckDetailWastes = swStTvmCheckDetailDTO.getSwStTvmCheckDetailWastes();
        if(CollectionUtil.isNotEmpty(swStTvmCheckDetailWastes)){
            //统计集合重复元素出现次数
            Map<String, Long> map5 = swStTvmCheckDetailWastes.stream().
                    collect(Collectors.groupingBy(x -> x.getTvmCode(), Collectors.counting()));
            for (Map.Entry<String, Long> tvm : map5.entrySet()) {
                if(!Long.valueOf(1).equals(tvm.getValue())){
                    return R.failed(StmConstans.failedInsert.replace("{TVMCODE}",tvm.getKey()));
                }
            }
        }
        String md5 = MD5.create().digestHex(swStTvmCheckDetailDTO.toString());
        if (noPass(SecurityUtils.getUser().getId(), "tvmSubmit", md5)) {
            return R.failed("请勿重复提交");
        }
        SwStTvmCheckDetail swStTvmCheckDetail = swStTvmCheckDetailDTO.getSwStTvmCheckDetail();
        SwStTvmCheckDetail checkDetail = swStTvmCheckDetailService.getById(swStTvmCheckDetail.getId());
        if(ObjectUtil.isNotEmpty(checkDetail)){
            String approvalStatus = checkDetail.getApprovalStatus();
            if("1".equals(approvalStatus)){
                return R.failed(StmConstans.failedEdit);
            }
        }
        swStTvmCheckDetailService.saveCheckDetailDataEntryLog(swStTvmCheckDetailDTO,id);
        swStTvmCheckDetailService.updateById(swStTvmCheckDetail);
        return R.ok(swStTvmCheckDetailService.saveOrUpdateStTvmCheckDetail(swStTvmCheckDetailDTO,id));
    }

    /**
     * 单个新增或者修改tvm详细日清点表（主表）
     *
     * @param swStTvmCheckDetailDTO TVM详细日清点表（主表）
     * @return 返回主表ID
     */
    @ApiOperation(value = "（主表）", notes = "单个修改tvm详细日清点表（主表）")
    @SysLog("单个修改tvm详细日清点表")
    @PutMapping("/update/onecashbox")
    @PreAuthorize("@pms.hasPermission('swsttvmcheckdetail_update_cashbox')")
    public R updateSwStOneCashBox(@RequestBody SwStTvmCheckDetailDTO swStTvmCheckDetailDTO) {
        return R.ok(swStTvmCheckDetailService.updateSwStOneCashBox(swStTvmCheckDetailDTO));
    }


    @ApiOperation(value = "导出Tvm钱箱清点数据", notes = "导出钱箱未卸载数据")
    @GetMapping("/export")
    public void export(Page page, SwStTvmCheckDetail swStTvmCheckDetail, HttpServletResponse response) {
        List<SwStTvmCheckDetail> records = swStTvmCheckDetailService.page(page, Wrappers.query(swStTvmCheckDetail)).getRecords();
        try {
            R<List<SysDictItem>> inputDataStatus = systemUserService.getDictByType(StmConstans.STM_INPUT_DATA_STATUS);
            List<SysDictItem> dictData = inputDataStatus.getData();
            //excel导出时候需要对已有的状态进行映射
            if (CollectionUtil.isNotEmpty(records) && CollectionUtil.isNotEmpty(dictData)) {
                Map<String, String> map = dictData.stream().collect(Collectors.toMap(SysDictItem::getValue, SysDictItem::getLabel));
                for (SwStTvmCheckDetail record : records) {
                    record.setApprovalStatus(map.get(record.getApprovalStatus()));
                }
            }
            response.setContentType("application/vnd.ms-excel");
            response.setCharacterEncoding("utf-8");
            String fileName = URLEncoder.encode("Tvm钱箱清点数据", "UTF-8");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName + System.currentTimeMillis() + ".xlsx");
            EasyExcel.write(response.getOutputStream(), SwStTvmCheckDetail.class).
                    sheet("Tvm钱箱清点数据").doWrite(records);
        } catch (IOException e) {
            log.error("Tvm钱箱清点数据导出失败");
        }
    }

    @Override
    public RedisTemplate<String, String> redisTemplate() {
        return redisTemplate;
    }
}
